/*******************************************************************
 * 外语翻译平台(translate) 
 *
 * 成都一亿信息技术公司 版权所有
 * 
 * Copyright (C) 2010 Transer Information Technology Co., Ltd.
 *
 * @Version : 1.0  2011-1-14 下午02:40:50
 *
 * TestJsonAction.java
 *
 *******************************************************************/
package com.transer.web.action.passport;

import java.io.PrintWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.transer.persistance.bean.Message;
import com.transer.web.action.TranserActionSupport;

/**
 * class defination are there
 * 
 * @author Mark
 * 
 * @version 1.0 ywengineer@gmail.com
 * 
 */
public class TestJsonAction extends TranserActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3391491393982411720L;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		Message msg = new Message();
		msg.setContent("<b>新消息</b>");
		msg.setCreateDate(new Date());
		msg.setId(123);
		msg.setStatus(false);
		msg.setUserID(12345);
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("application/json;charset=utf-8");
		PrintWriter writer = response.getWriter();
		writer.write(JSONObject.fromObject(msg).toString());
		writer.flush();
		writer.close();
		return null;
	}

	public static void main(String[] args) {
		Map<String, Object> msg = new HashMap<String, Object>();
		msg.put("id", 123);
		msg.put("name", "string");
		System.out.println(JSONObject.fromObject(msg).toString());
	}
}
